#include "Formes/MetaBalle.hpp"

#include "Materiaux/AplatCouleur.hpp"

#include "Objet.hpp"
#include "Rayon.hpp"

#include "Environnement.hpp"
#include "Lumieres/Source.hpp"
#include "Camera.hpp"
#include "Image/Image.hpp"
#include "Image/ImageFilePng.hpp"

#include <iostream>
#include <vector>

using namespace std;

int main( int argc, char * argv[] )
{
    vector< Coord > pos;

    pos.push_back( Coord( 0., -2., 0. ) );
    pos.push_back( Coord( 0., 2., 0. ) );

    Forme * volume = new MetaBalle( pos, VecteurU( 1., 0., 0. ), Vecteur( 0., 10, 0. ), 3., 1. );
    Materiau * habit = new AplatCouleur( 0.2, 0.0, 1.0, 0.8, Couleur( 255u, 0u, 0u ) );

    volume -> affiche( cout );

    Objet *obj = new Objet( habit, volume );

    Rayon ray( Coord( 150., 0.5, 0.3  ), VecteurU( -1., 0., 0. ) );

    cout << obj -> volume() -> trouveIntersection( ray ) << endl;

    Environnement* env = new Environnement( Couleur( 0u, 0u, 255u ) );

    env -> ajouterObjet( obj );

    Lumiere* lum = new Source( Couleur( 255u, 255u, 255u ), Coord( 0., 30., 0. ) );

    env -> ajouterLumiere( lum );

    Image* ecran = new Image( 400u, 40u );

    Camera* cam = new Camera( Coord( 15., 0., 0. ), VecteurU( -1., 0., 0. ), VecteurU( 0., 0., 1. ),
                              1000., ecran, env, 1u, 1., 0 );

    cam -> genereImage();

    ImageFilePng mon_image( cam -> film(), "Test.png" );
    mon_image.affiche();

    delete cam;
    cam = 0;
    delete ecran;
    ecran = 0;
    delete env;
    env = 0;
    delete obj;
    obj = 0;
    delete volume;
    volume = 0;
    delete habit;
    habit = 0;

    return 0;
}
